SPB Git

Repository Public

route.ts 872 B 17 lines typescript

1import { getFigureFile, getPreviewCourse } from "@/lib/content";2import { notFoundResponse, serveBytes } from "@/lib/serve";3import { currentSession } from "@/lib/studio/guard";45export const dynamic = "force-dynamic";67/** Figures of the working copy, for the private preview of a signed-in editor. */8async function handle(request: Request, { params }: { params: Promise<{ path: string[] }> }) {9  if (!(await currentSession())) return notFoundResponse();10  const [sessionId, ...rest] = (await params).path;11  const session = (await getPreviewCourse()).sessions.find((s) => s.id === sessionId);12  const file = session ? await getFigureFile(session, rest.join("/")) : null;13  if (!file || !("bytes" in file)) return notFoundResponse();14  return serveBytes(file.bytes, "image/svg+xml", request, { cache: "private, no-store" });15}16export { handle as GET, handle as HEAD };17
Files main
Menu

Theme